package br.com.affero.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.affero.bean.Document;
import br.com.affero.facade.DomainFacade;
import br.com.affero.util.UploadedFile;

public class DeleteDocumentAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		Integer id = Integer.parseInt(request.getParameter("id"));		
		
		Document document = DomainFacade.getInstance().getDocument(id);
		UploadedFile.delete(document.getFilePath());
		
		DomainFacade.getInstance().deleteDocument(document);
		
		return mapping.findForward("list");
	}
	
}
